package com.lechi.web.controller;

import com.lechi.web.common.core.controller.BaseController;
import com.lechi.web.common.core.domain.AjaxResult;
import com.lechi.web.common.core.domain.entity.SysUser;
import com.lechi.web.common.core.domain.model.LoginUser;
import com.lechi.web.common.core.page.TableDataInfo;
import com.lechi.web.service.IIotUpgradeLogService;
import com.lechi.web.system.domain.IotUpgradeLog;
import com.lechi.web.vo.IotUpgradeLogVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 升级日志记录Controller
 *
 * @author yangguang
 * @date 2024 -07-10
 */
@RestController
@RequestMapping("/iot/app/log")
@RequiredArgsConstructor
public class IotUpgradeLogController extends BaseController {

    private final IIotUpgradeLogService iotUpgradeLogService;

    /**
     * 查询升级日志记录列表
     *
     * @param iotUpgradeLogVo the iot upgrade log vo
     * @return the table data info
     */
    @GetMapping("/list")
    //    @PreAuthorize("@ss.hasPermi('iot:log:query')")
    public TableDataInfo list(IotUpgradeLogVo iotUpgradeLogVo) {
        startPage();
        IotUpgradeLog iotUpgradeLog = new IotUpgradeLog();
        BeanUtils.copyProperties(iotUpgradeLogVo, iotUpgradeLog);
        LoginUser loginUser = getLoginUser();
        SysUser user = loginUser.getUser();
        if (!user.isAdmin()) {
            iotUpgradeLog.setCreateBy(user.getUserName());
        }
        List<IotUpgradeLog> list = iotUpgradeLogService.selectIotUpgradeLogList(iotUpgradeLog);
        return getDataTable(list);
    }


    /**
     * 获取升级日志记录详细信息
     *
     * @param id the id
     * @return the info
     */
    @GetMapping(value = "/{id}")
    //    @PreAuthorize("@ss.hasPermi('iot:log:remove')")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        IotUpgradeLog iotUpgradeLog = iotUpgradeLogService.selectIotUpgradeLogById(id);
        return AjaxResult.success(iotUpgradeLog);
    }
}
